# https://leetcode.cn/problems/contains-duplicate-ii/?envType=problem-list-v2&envId=array
from typing import List


class Solution:
    def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
        for i in range(len(nums)):
            for j in range(len(nums)):
                try:
                    if nums[i] == nums[j + 1] and abs(i - (j + 1)) <= k:
                        return True
                except IndexError:
                    continue
        return False


if __name__ == '__main__':
    s = Solution()
    print(s.containsNearbyDuplicate([1, 2, 3, 1, 2, 3], 2))
